package org.hot100_3;

public class leetcode437 {
    public int pathSum(TreeNode root, int targetSum) {

        if (root==null){
            return 0;
        }

        DFS(root,targetSum,0);

        pathSum(root.left,targetSum);

        pathSum(root.right,targetSum);

        return count;
    }

    int count = 0;

    private void DFS(TreeNode root, int targetSum, long sum) {
        if (root == null) {
            return;
        }

        sum += root.val;
        if (sum == targetSum) {
            count++;
        }

        DFS(root.left, targetSum, sum);

        DFS(root.right, targetSum, sum);

    }
}
